package com.sunshine.ssm.util;

import org.slf4j.Logger;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 */
public final class Environment {

	/**
	 * 构造方法私有化
	 */
	private Environment() {
	}


	private static List<Entry> info = new ArrayList<>();

	static {
		list();
	}
	
	public static void put(String k, String v) {
		info.add(new Environment.Entry(k, v));
	}

	private static void list() {
		try {
			put("host.name", InetAddress.getLocalHost().getCanonicalHostName());
		} catch (UnknownHostException var2) {
			put("host.name", "<NA>");
		}
		put("java.version", System.getProperty("java.version", "<NA>"));
		put("java.vendor", System.getProperty("java.vendor", "<NA>"));
		put("java.home", System.getProperty("java.home", "<NA>"));
		put("java.class.version", System.getProperty("java.class.version", "<NA>"));
		put("java.class.path", System.getProperty("java.class.path", "<NA>"));
		put("java.library.path", System.getProperty("java.library.path", "<NA>"));
		put("java.io.tmpdir", System.getProperty("java.io.tmpdir", "<NA>"));
		put("java.compiler", System.getProperty("java.compiler", "<NA>"));
		put("os.name", System.getProperty("os.name", "<NA>"));
		put("os.arch", System.getProperty("os.arch", "<NA>"));
		put("os.version", System.getProperty("os.version", "<NA>"));
		put("user.name", System.getProperty("user.name", "<NA>"));
		put("user.home", System.getProperty("user.home", "<NA>"));
		put("user.dir", System.getProperty("user.dir", "<NA>"));
		put("user.timezone", System.getProperty("user.timezone", "<NA>"));
		put("user.language", System.getProperty("user.language", "<NA>"));
	}

	public static void logEnv(String msg, Logger log) {
		Iterator<Entry> i$ = info.iterator();
		while (i$.hasNext()) {
			Environment.Entry e = i$.next();
			log.info(msg + e.toString());
		}
	}

	public static class Entry {

		private String k;
		private String v;

		public Entry(String k, String v) {
			this.k = k;
			this.v = v;
		}

		public String getKey() {
			return this.k;
		}

		public String getValue() {
			return this.v;
		}

		public String toString() {
			return this.k + "=" + this.v;
		}
	}

}
